#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
using namespace std;

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int min = INT_MAX;
        int left = 0, right = 0;
        int sum = 0;
        while (right < nums.size())
        {
            while (right < nums.size() && sum < target) sum += nums[right++];
            while (left < right&& sum >= target) sum -= nums[left++];
            if (left == 0 && right == nums.size()) return 0;
            min = min > right - left + 1 ? right - left + 1 : min;
        }
        if (min == INT_MAX) return 0;
        return min;
    }
};